package com.xbs.dao.hitchhiking;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import com.xbs.dao.conn.BaseDao;
import com.xbs.dao.conn.ParamSet;
import com.xbs.dao.conn.RowDatas;
import com.xbs.entity.CommonOrderEntity;
import com.xbs.entity.HitchhikeEntity;
import com.xbs.entity.OrderMoney;
import com.xbs.entity.RentEntity;
import com.xbs.entity.StoreEntity;
import com.xbs.entity.TimeEntity;

/**
 * 顺风车的订单dao
 * 
 * @author dell
 */
public class HitchOrderDao extends BaseDao{
	private RowDatas<CommonOrderEntity> order;//声明一个订单对象
	private RowDatas<TimeEntity> time;//声明一份时间订单表
	private RowDatas<RentEntity> rent;//声明一个实际租车人信息表
	
	public HitchOrderDao(){
		order = new OrderData();
		time = new TimeData();
		rent = new RentData();
	}
	
	/**
	 * 1.向订单表插入一条数据
	 */
	public int getOrder(String coid,String rentid,String cartype,
			String gaddress,String raddress,String orderkind,
			Double planmoney,String gstore,String rstore,String costatus){
		int row = 0;
		String sql = "insert into tb_common_order(co_id,"
				+ " co_rent_idcard,co_car_type,"
				+ " co_get_address,co_return_address,co_order_kind,"
				+ " co_plan_pay_money,co_get_store,co_return_store,co_order_status) "
				+ " values(?,?,?,?,?,?,?,?,?,?)";
		row = updateExecuted(sql, new ParamSet(coid,rentid,cartype,
				gaddress,raddress,orderkind,planmoney,gstore,rstore,costatus));
		return row;
	}
	/**
	 * 2.向时间表添加数据
	 */
	public int getOrderTime(String orderid,Timestamp gplantime,Timestamp rplantime,String paytime){
		int row = 0;
		String sql="insert into tb_time(time_order_id,time_plan_get,"
				+ "time_plan_return,time_order_pay) "
				+ "values(?,?,?,?)";
		row = updateExecuted(sql, new ParamSet(orderid,gplantime,rplantime,paytime));
		return row;
	}
	
	/**
	 * 3.向实际租车人表中填写一条数据
	 */
	public int getRent(String user_idcard,String rent_name,
			String rent_idcard,String rent_telphone,String coid){
		int row = 0;
		String sql = " insert into tb_rent(user_idcard,"
				+ " rent_name,rent_idcard,rent_telphone,co_id) "
				+ " values(?,?,?,?,?)";
		row = updateExecuted(sql, new ParamSet(user_idcard,rent_name,
				rent_idcard,rent_telphone,coid));
		return row;
	}
	
	/**
	 * 4.向订单金钱表插入一条数据
	 */
	public int getMoney(OrderMoney om){
		int row = 0;
		String sql = "insert into tb_order_money (order_id,"
				+ " order_rent_money,order_guarantee_money,"
				+ " order_insurance_money,order_service_money,"
				+ " order_amount_money,order_car_damage_money) "
				+ " values (?,0,0,0,0,0,0);";
		row = updateExecuted(sql, new ParamSet(om.getOrder_id())) ;
		return row;
	}
	
	/**
	 *  1.内部类来实现接口，订单表
	 * @author dell
	 */
	private class OrderData implements RowDatas<CommonOrderEntity>{

		@Override
		public CommonOrderEntity getRowData(ResultSet rs) throws SQLException {
			CommonOrderEntity order = new CommonOrderEntity();
			order.setCo_car_id(rs.getString("co_card_id"));
			order.setCo_car_type(rs.getString("co_car_type"));
			order.setCo_get_address(rs.getString("co_get_address"));
			order.setCo_return_store(rs.getString("co_return_store"));
			order.setCo_get_store(rs.getString("co_get_store"));
			order.setCo_id(rs.getString("co_id"));
			order.setCo_order_kind(rs.getString("co_order_kind"));
			order.setCo_plan_pay_money(rs.getDouble("co_plan_pay_money"));
			order.setCo_rent_idcard(rs.getString("co_rent_idcard"));
			order.setCo_return_address(rs.getString("co_return_address"));
			order.setCo_order_status(rs.getString("co_order_status"));
			return order;
		}
		
	}
	/**
	 * 2.内部类来实现接口，时间表
	 * @author dell
	 */
	private class TimeData implements RowDatas<TimeEntity>{

		@Override
		public TimeEntity getRowData(ResultSet rs) throws SQLException {
			TimeEntity time = new TimeEntity();
			time.setTime_order_id(rs.getString("time_order_id"));
			time.setTime_plan_get(rs.getTimestamp("time_plan_get"));
			time.setTime_plan_return(rs.getTimestamp("time_plan_return"));
			time.setTime_order_pay(rs.getTimestamp("time_order_pay"));
			return time;
		}
		
	}
	
	/**
	 * 2.内部类来实现接口，实际租车人表
	 * @author dell
	 */
	private class RentData implements RowDatas<RentEntity>{

		@Override
		public RentEntity getRowData(ResultSet rs) throws SQLException {
			RentEntity rent = new RentEntity();
			rent.setRent_idcard(rs.getString("rent_idcard"));
			rent.setCo_id(rs.getString("co_id"));
			rent.setRent_telephone(rs.getString("rent_telphone"));
			rent.setRent_name(rs.getString("rent_name"));
			rent.setUser_idcard(rs.getString("user_idcard"));
			return rent;
		}
		
	}
	
}
